﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;


namespace MiaProject
{
    class Platform2D
    {
        public List<Vector2> points;
        public List<Vector2> pointsMove;
        public Vector2 pos;
        public List<Vector2> normal;
        public Texture2D texture;
        public Boolean fgshow;
        public float angle;
        private Vector2 dir;
        private int currentPoint;
        public Trigger trigger;
        public Boolean hasTrigger;

        public Platform2D()
        {
            fgshow = true;
            hasTrigger = false;
            angle = 0;
            dir = Vector2.Zero;
            points = new List<Vector2>();
            normal = new List<Vector2>();
            pointsMove = new List<Vector2>();
            currentPoint = 0;
        }
        public void update(GameTime gameTime)
        {
            if(pointsMove.Count==0)
                return;
            if (this.hasTrigger && !this.trigger.status)
                return;
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (Vector2.Distance(this.pos, this.pointsMove[this.currentPoint]) <= 5)
            {
                this.currentPoint++;
                if (this.currentPoint >= this.pointsMove.Count)
                    this.currentPoint = 0;

                dir = this.pointsMove[this.currentPoint] - pos;
                dir.Normalize();
            }
            
            this.pos.X += 30 * elapsed * this.dir.X;
            
        }
    }
}


